package com.gs.wzweather.service.impl;

import com.gs.wzweather.dao.StatisticsDao;
import com.gs.wzweather.bo.Response;
import com.gs.wzweather.entity.Site;
import com.gs.wzweather.service.StatisticsService;
import com.gs.wzweather.utils.Constant;
import com.gs.wzweather.utils.ParseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
@Component
@Repository
@Service
@Controller
*/

/*累计降水*/
@Service
public class StatisticsServiceImpl implements StatisticsService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    StatisticsDao statisticsDao;

    @Override
    public Response getWea(String time, String element) {
        Response response = new Response();
        List<Site> sites = statisticsDao.queryWea(time, element);
        for (Site site : sites) {
            if (site != null && site.getWeather() != null) {
                logger.info("降水无数据站点->{}", site.getStationId());
                site.getWeather().setValue("0.0");
            }
        }
        if (sites != null) {
            response.setReturnCode(Constant.Response.SUCCESS_CODE);
            response.setSiteList(ParseUtil.formatSites(sites));
        }
        return response;
    }
}
